<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - entropy_encoder_model.cpp</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2005  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font>

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>sstream<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>string<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>ctime<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>cstdlib<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>entropy_encoder_model.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>entropy_decoder_model.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>entropy_encoder.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>dlib<font color='#5555FF'>/</font>entropy_decoder.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='tester.h.html'>tester.h</a>"

<font color='#0000FF'>namespace</font>  
<b>{</b>
    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> test;
    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> std;
    <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> dlib;

    logger <b><a name='dlog'></a>dlog</b><font face='Lucida Console'>(</font>"<font color='#CC0000'>test.entropy_coder_model</font>"<font face='Lucida Console'>)</font>;

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> ee,
        <font color='#0000FF'>typename</font> ed
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='entropy_encoder_model_kernel_test'></a>entropy_encoder_model_kernel_test</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <font color='#009900'>/*!
        requires
            - ee is an implementation of entropy_encoder_model/entropy_encoder_model_kernel_abstract.h            
              the alphabet_size for ee is 256
            - ed is an implementation of entropy_decoder_model/entropy_decoder_model_kernel_abstract.h            
              the alphabet_size for ed is 256
            - ee and ed must share the same kernel number
        ensures
            - runs tests on ee and ed for compliance with the specs 
    !*/</font>
    <b>{</b>        

        <font color='#BB00BB'>print_spinner</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>srand</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>int</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#BB00BB'>time</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> ee::entropy_encoder_type ee_type;
        <font color='#0000FF'>typedef</font> <font color='#0000FF'>typename</font> ed::entropy_decoder_type ed_type;



        <b>{</b>

            ee_type ecoder;
            ed_type dcoder;

            ee <font color='#BB00BB'>elen</font><font face='Lucida Console'>(</font>ecoder<font face='Lucida Console'>)</font>;
            ed <font color='#BB00BB'>dlen</font><font face='Lucida Console'>(</font>dcoder<font face='Lucida Console'>)</font>;
            ee <font color='#BB00BB'>elit</font><font face='Lucida Console'>(</font>ecoder<font face='Lucida Console'>)</font>;
            ed <font color='#BB00BB'>dlit</font><font face='Lucida Console'>(</font>dcoder<font face='Lucida Console'>)</font>;


            istringstream sin;
            ostringstream sout;

            ecoder.<font color='#BB00BB'>set_stream</font><font face='Lucida Console'>(</font>sout<font face='Lucida Console'>)</font>;


            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> temp;


            elen.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            elit.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>9</font><font face='Lucida Console'>)</font>;

            elen.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            elit.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;

            elen.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            elit.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>4</font><font face='Lucida Console'>)</font>;

            elen.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            elit.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;

            elen.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            elit.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;

            elen.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            elit.<font color='#BB00BB'>encode</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;







            ecoder.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            sin.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font>sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            dcoder.<font color='#BB00BB'>set_stream</font><font face='Lucida Console'>(</font>sin<font face='Lucida Console'>)</font>;


            dlen.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            dlit.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>9</font><font face='Lucida Console'>)</font>;

            dlen.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            dlit.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;

            dlen.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            dlit.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>4</font><font face='Lucida Console'>)</font>;

            dlen.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            dlit.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;

            dlen.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            dlit.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font>;

            dlen.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            dlit.<font color='#BB00BB'>decode</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_TEST</font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;




        <b>}</b>

    <b>}</b>




    <font color='#0000FF'>class</font> <b><a name='entropy_encoder_model_tester'></a>entropy_encoder_model_tester</b> : <font color='#0000FF'>public</font> tester
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <b><a name='entropy_encoder_model_tester'></a>entropy_encoder_model_tester</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> :
            tester <font face='Lucida Console'>(</font>"<font color='#CC0000'>test_entropy_coder_model</font>",
                    "<font color='#CC0000'>Runs tests on the entropy_encoder_model and entropy_decoder_model components.</font>"<font face='Lucida Console'>)</font>
        <b>{</b><b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='perform_test'></a>perform_test</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>typedef</font> entropy_encoder::kernel_2a_c ee;
            <font color='#0000FF'>typedef</font> entropy_decoder::kernel_2a_c ed;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing kernel_1a</font>";
            entropy_encoder_model_kernel_test<font color='#5555FF'>&lt;</font>
                entropy_encoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ee<font color='#5555FF'>&gt;</font>::kernel_1a,
                entropy_decoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ed<font color='#5555FF'>&gt;</font>::kernel_1a<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing kernel_2a</font>";
            entropy_encoder_model_kernel_test<font color='#5555FF'>&lt;</font>
                entropy_encoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ee<font color='#5555FF'>&gt;</font>::kernel_2a,
                entropy_decoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ed<font color='#5555FF'>&gt;</font>::kernel_2a<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing kernel_3a</font>";
            entropy_encoder_model_kernel_test<font color='#5555FF'>&lt;</font>
                entropy_encoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ee<font color='#5555FF'>&gt;</font>::kernel_3a,
                entropy_decoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ed<font color='#5555FF'>&gt;</font>::kernel_3a<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing kernel_4a</font>";
            entropy_encoder_model_kernel_test<font color='#5555FF'>&lt;</font>
                entropy_encoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ee<font color='#5555FF'>&gt;</font>::kernel_4a,
                entropy_decoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ed<font color='#5555FF'>&gt;</font>::kernel_4a<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing kernel_4b</font>";
            entropy_encoder_model_kernel_test<font color='#5555FF'>&lt;</font>
                entropy_encoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ee<font color='#5555FF'>&gt;</font>::kernel_4b,
                entropy_decoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ed<font color='#5555FF'>&gt;</font>::kernel_4b<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing kernel_5a</font>";
            entropy_encoder_model_kernel_test<font color='#5555FF'>&lt;</font>
                entropy_encoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ee<font color='#5555FF'>&gt;</font>::kernel_5a,
                entropy_decoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ed<font color='#5555FF'>&gt;</font>::kernel_5a<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing kernel_5c</font>";
            entropy_encoder_model_kernel_test<font color='#5555FF'>&lt;</font>
                entropy_encoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ee<font color='#5555FF'>&gt;</font>::kernel_5c,
                entropy_decoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ed<font color='#5555FF'>&gt;</font>::kernel_5c<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            dlog <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> LINFO <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>testing kernel_6a</font>";
            entropy_encoder_model_kernel_test<font color='#5555FF'>&lt;</font>
                entropy_encoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ee<font color='#5555FF'>&gt;</font>::kernel_6a,
                entropy_decoder_model<font color='#5555FF'>&lt;</font><font color='#979000'>256</font>,ed<font color='#5555FF'>&gt;</font>::kernel_6a<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <b>}</b>
    <b>}</b> a;

<b>}</b>


</pre></body></html>